﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Common;
using System.Configuration;
using System.IO;

namespace EHR18
{
    public partial class FrmModuleConfig : BaseChild
    {
        string CurrentModule = ConfigurationManager.AppSettings["CurrentModel"];
        public FrmModuleConfig()
        {
            InitializeComponent();
        }
        public FrmModuleConfig(string Module)
        {
            CurrentModule = Module;
            InitializeComponent();
        }
        private void tableLayoutPanel1_Paint(object sender, PaintEventArgs e)
        {

        }

        private void FrmModuleConfig_Load(object sender, EventArgs e)
        {
            
            label1.Text = CurrentModule;
            string path = Path.GetFullPath(string.Format("./Configs/{0}.xml", CurrentModule));
            if (!File.Exists(path))
            {
                string path2 = Path.GetFullPath(string.Format("./Configs/{0}.xml", "template"));
                var obj = ConfigEx.DeserializeFromXml<ModuleConfig>(path2);           
                obj.SerializeToXml(path);
            }
            propertyGrid1.SelectedObject = ConfigEx.DeserializeFromXml<ModuleConfig>(path);
        }

        private void btnCommit_Click(object sender, EventArgs e)
        {
            ((ModuleConfig)propertyGrid1.SelectedObject).SerializeToXml(string.Format("./Configs/{0}.xml", CurrentModule));
            Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            Close();
        }
    }
}
